package com.atguigu.springanalysis.service;

import com.atguigu.springanalysis.event.BlackListEvent;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class EmailService implements ApplicationEventPublisherAware {
    private List<String> blackList = Arrays.asList("A","B");
    private ApplicationEventPublisher applicationEventPublisher;
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.applicationEventPublisher = applicationEventPublisher;
    }
    public void sendEmail(String address,String text){
        if(blackList.contains(address)){
            BlackListEvent blackListEvent = new BlackListEvent(this,address,text);
            this.applicationEventPublisher.publishEvent(blackListEvent);
        }
    }
}
